import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
// import Blogs from '../views/Blogs.vue'
import BlogEdit from '../views/BlogEdit.vue'
import BlogDetail from '../views/BlogDetail.vue'
import UserHome from "../views/UserHome";
import Manager from "../views/Manager";
import Register from "../views/Register";
import Router from 'vue-router'
import Manage2 from "../views/Manage2";
import userManage from "../views/userManage";
import blogManage from "../views/blogManage";
import labelManage from "../views/labelManage";
import commentManage from "../views/commentManage";
import Grounds from "../views/Grounds";
import HotFavorites from "../views/HotFavorites";
import quesManage from "../views/quesManage";
import collectionsManage from "../views/collectionsManage";
import HotWebs from "../views/HotWebs";
import urlManage from "../views/urlManage";
import mobile from "../mobile/components/mobile";
import mindex from "../mobile/views/mindx";
import edit from "../mobile/views/edit";
import user from "../mobile/views/user";
import apps from "../mobile/views/apps";
import mlogin from "../mobile/components/mlogin";
import mblogdetail from "../mobile/views/mblogdetail";

Vue.use(VueRouter)
/**
 * 路由配置
 *      有个建议  加上name属性哈  调用方便
 *      还有权限配置  关键字meta
 */



const routes = [
    {
        path: '/',
        name: 'Index',
        redirect: {name: "Blogs"}
        //首页重定向到 blogs
    },

    {
        path: '/mobile',
        name: 'mobile',
        component: mobile,
        children: [
            {
                path: '/mindex',
                name: 'mindex',
                // component: mindex
                component: resolve => require(['@/mobile/views/mindx.vue'],resolve),
            },
            {
                path: '/edit',
                name: 'edit',
                // component: edit,
                component: resolve => require(['@/mobile/views/edit.vue'],resolve),
                meta: {
                    requireAuth: true
                }
            },
            {
                path: '/user',
                name: 'user',
                // component: user,
                component: resolve => require(['@/mobile/views/user.vue'],resolve),
                meta: {
                    requireAuth: true
                }
            },
            {
                path: '/apps',
                name: 'apps',
                // component: apps,
                component: resolve => require(['@/mobile/views/apps.vue'],resolve),
                meta: {
                    requireAuth: true
                }
            },

            {
                //需要有编辑的ID   注意格式  :blogid可作为参数
                path: '/:blogId/edit',
                name: 'edit2',
                // component: edit,
                component: resolve => require(['@/mobile/views/edit.vue'],resolve),
                meta: {
                    requireAuth: true
                }
            },
        ]
    },
    {
        path: '/mblog',
        name: 'mblog',
        // component: mblogdetail,
        component: resolve => require(['@/mobile/views/mindx.vue'],resolve),
        meta: {
            requireAuth: true
        }
    },

    {
        path: '/blogs',
        name: 'Blogs',
        // component: Blogs
        component: resolve => require(['@/views/Blogs.vue'],resolve)
    },
    {
        path: '/grounds',
        name: 'Grounds',
        // component: Grounds
        component: resolve => require(['@/views/Grounds.vue'],resolve)
    },
    {
        path: '/hotfavorites',
        name: 'HotFavorites',
        // component: HotFavorites
        component: resolve => require(['@/views/HotFavorites.vue'],resolve)
    },
    {
        path: '/hotwebs',
        name: 'HotWebs',
        // component: HotWebs
        component: resolve => require(['@/views/HotWebs.vue'],resolve)
    },
    {
        path: '/login',
        name: 'Login',
        // component: Login
        component: resolve => require(['@/views/Login.vue'],resolve)

    },
    {
        path: '/mlogin',
        name: 'mlogin',
        // component: mlogin
        component: resolve => require(['@/mobile/components/mlogin.vue'],resolve)
    },
    {
        path: '/mregister',
        name: 'mregister',
        // component: mlogin
        component: resolve => require(['@/mobile/components/mregister.vue'],resolve)
    },
    {
        path: '/register',
        name: 'Register',
        // component: Register
        component: resolve => require(['@/views/Register.vue'],resolve)
    },
    {
        path: '/manager',
        name: 'Manager',
        // component: Manager,
        component: resolve => require(['@/views/Manager.vue'],resolve),
        meta: {
            requireAuth: true,
            isAdmin:true
        }
    },
    {
        path: '/blog/add',
        name: 'BlogAdd',
        // component: BlogEdit,
        component: resolve => require(['@/views/BlogEdit.vue'],resolve),
        meta: {
            requireAuth: true
        }
    },
    {
        path: '/userhome',
        name: 'UserHome',
        // component: UserHome,
        component: resolve => require(['@/views/UserHome.vue'],resolve),
        meta: {
            requireAuth: true
        }
    },
    {
        path: '/blog/:blogId?',
        name: 'BlogDetail',
        component: BlogDetail,  //detail之所以不用懒加载是因为  评论模块的原因 测试一下
        // component: resolve => require(['@/views/BlogDetail.vue'],resolve),
        meta: {
            requireAuth: true
        }
    },

    {
        path: '/mblog/:blogId?',
        name: 'mblogdetail',
        // component: mblogdetail,
        component: resolve => require(['@/mobile/views/mblogdetail.vue'],resolve),
        meta: {
            requireAuth: true
        }
    },


    //这之间还有顺序关系？？？  短的在上  测试一下
    {
        //需要有编辑的ID   注意格式  :blogid可作为参数
        path: '/blog/:blogId/edit',
        name: 'BlogEdit',
        // component: BlogEdit,
        component: resolve => require(['@/views/BlogEdit.vue'],resolve),
        meta: {
            requireAuth: true
        }
    },



    {
        path: '/manage2',
        name: 'Manage2',
        // component: Manage2,
        component: resolve => require(['@/views/Manage2.vue'],resolve),
        meta: {
            requireAuth: true,
            isAdmin:true
        },
        children: [
            {
                path: '/manage2/userManage',
                name: 'UserManage',
                // component: userManage
                component: resolve => require(['@/views/userManage.vue'],resolve),
            },
            {
                path: '/manage2/blogManage',
                name: 'BlogManage',
                // component: blogManage
                component: resolve => require(['@/views/blogManage.vue'],resolve),
            },
            {
                path: '/manage2/labelManage',
                name: 'LabelManage',
                // component: labelManage
                component: resolve => require(['@/views/labelManage.vue'],resolve),
            },

            {
                path: '/manage2/quesManage',
                name: 'QuesManage',
                // component: quesManage
                component: resolve => require(['@/views/quesManage.vue'],resolve),
            },

            {
                path: '/manage2/commentManage',
                name: 'CommentManage',
                // component: commentManage
                component: resolve => require(['@/views/commentManage.vue'],resolve),
            },
            {
                path: '/manage2/collectionsManage',
                name: 'CollectionsManage',
                // component: collectionsManage
                component: resolve => require(['@/views/collectionsManage.vue'],resolve),
            },
            {
                path: '/manage2/urlManage',
                name: 'UrlManage',
                // component: urlManage
                component: resolve => require(['@/views/urlManage.vue'],resolve),
            },
        ]
    },

]


//自动生成的哈
const router = new VueRouter({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes
})

/**
 * 重写路由的push方法    logout那有解释
 */
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(error => error)
}


export default router
